package com.demo.iodemo;

import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

import com.alibaba.excel.EasyExcelFactory;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.metadata.BaseRowModel;
import com.alibaba.excel.metadata.Sheet;

/**
 * 一个简单的EasyExcel示例
 * @author xiangty
 * 参考文档：
 * 		https://github.com/alibaba/easyexcel
 * 		https://blog.csdn.net/biejiuyingshang/article/details/90170170
 *
 */
public class EasyExcelDemo {

	public static void main(String[] args) throws Exception {
		OutputStream outputStream = new FileOutputStream("D:\\test.xlsx");

		ExcelWriter writer = EasyExcelFactory.getWriter(outputStream);

		Sheet sheet = new Sheet(1, 0,Info2.class);

		sheet.setSheetName("这是第一个sheet页");

		List<Info2> data = new ArrayList<Info2>();
		Info2 info2 = null;
		for (int i = 0; i < 10; i++) {
			info2 = new Info2("value-" + i);
			data.add(info2);
		}
		writer.write(data,sheet);
		writer.finish();
		outputStream.close();
	}

}


class Info2 extends BaseRowModel{

	// index=0 表示第一列，列名为“姓名”
	@ExcelProperty(value="姓名",index=0)
	private String value;

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public Info2() {
		super();
	}

	public Info2(String value) {
		super();
		this.value = value;
	}

	@Override
	public String toString() {
		return "Info2 [value=" + value + "]";
	}
	
}